package ch07_GUI编程;

import javax.swing.*;
import java.awt.*;

public class GridBagLayoutDemo {
	public static void main(String[] args) {
		new GridBagLayoutDemo().init();
	}
	void init() {
		BaseFrame f = new BaseFrame("GridBagLayout Demo");
		f.setLayout(new GridBagLayout());

		JLabel labFace = new JLabel(ImageFactory.create("QQ.png"));
		JLabel labReg = new JLabel("ע���˺�");
		JLabel labFindPsw = new JLabel("�һ�����");
		JTextField tfId = new JTextField();
		JPasswordField tfPsw  =new JPasswordField();
		JCheckBox cbRemPsw = new JCheckBox("��ס����");
		JCheckBox cbAutoLogin = new JCheckBox("�Զ���¼");
		JButton btnExit = new JButton("�ر�");
		JButton btnLogin = new JButton("��¼");

		GridBagConstraints c = new GridBagConstraints();

		//ͷ���ǩ
		c.gridx= c.gridy =0;
		c.gridheight=3;
		f.add(labFace,c);

		//�˺ſ�
		c.gridx = 1;
		c.gridwidth = 2;
		c.gridheight = 1;
		c.weightx=1.0;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.insets = new Insets(0,0,4,0);
		f.add(tfId,c);

		//�����
		c.gridy = 1;
		f.add(tfPsw,c);

		//ע���˺ű�ǩ
		c = new GridBagConstraints();
		c.gridx = 3;
		c.gridy = 0;
		c.insets = new Insets(0,0,4,0);
		f.add(labReg,c);

		//�һ������ǩ
		c.gridy = 1;
		f.add(labFindPsw,c);

		//��ס���븴ѡ��
		c.gridx = 1;
		c.gridy = 2;
		f.add(cbRemPsw,c);

		//�Զ���¼��ѡ��
		c.gridx= 2;
		f.add(cbAutoLogin,c);

		//�رհ�ť
		c.gridx=2;
		c.gridy=3;
		c.anchor=GridBagConstraints.SOUTHEAST;
		c.insets= new Insets(20,0,0,5);
		f.add(btnExit,c);

		//��¼��ť
		c.gridx = 3;
		f.add(btnLogin,c);

		//f.setIconImage(new ImageIcon("images/java.png").getImage());
		f.showMe();

	}
}
